package cn.com.dealme.domain.model;

import java.util.HashSet;
import java.util.Set;

import cn.com.dealme.domain.model.exception.PublishModeException;
import cn.com.dealme.domain.vo.PublishModeVO;

public class PublishMode {
	
	private Long id;

	private PublishModeVO attributes;
	
	private Set<Catagory> topCatagorySet;
	
	public PublishMode() {
	}
	
	public PublishMode(Long id) {
		this.id = id;
	}
	
	public PublishMode(PublishModeVO attributes, Set<Catagory> topCatagorySet) {
		if(null == attributes) {
			throw new PublishModeException(PublishModeException.ATTR_NULL_EXCEPTION);
		}
		if(null == topCatagorySet) {
			topCatagorySet = new HashSet<Catagory>();
		}
		this.attributes = attributes;
		this.topCatagorySet = topCatagorySet;
	}
	
	public void update(PublishModeVO attributes) {
		if(null == attributes) {
			throw new PublishModeException(PublishModeException.ATTR_NULL_EXCEPTION);
		}
		this.attributes = attributes;
	}
	
	public void addTopCatagory(Catagory top) {
		if(!top.topable()) {
			throw new PublishModeException(PublishModeException.NOT_TOP_CATAGORY_EXCEPTION);
		}
		this.topCatagorySet.add(top);
	}
	
	public void removeTopCatagory(Catagory top) {
		this.topCatagorySet.remove(top);
	}

	public PublishModeVO getAttributes() {
		return attributes;
	}

	public Set<Catagory> getTopCatagorySet() {
		return topCatagorySet;
	}
	
	public Long getId() {
		return id;
	}

	protected void setId(Long id) {
		this.id = id;
	}
	
	protected void setAttributes(PublishModeVO attributes) {
		this.attributes = attributes;
	}

	protected void setTopCatagorySet(Set<Catagory> topCatagorySet) {
		this.topCatagorySet = topCatagorySet;
	}

	@Override
	public boolean equals(Object obj) {
		if(null == obj) return false;
		if(!(obj instanceof PublishMode)) return false;
		if(this.id.equals(((PublishMode)obj).id)) {
			return true;
		}
		return false;
	}

	@Override
	public int hashCode() {
		return this.id.hashCode();
	}
}
